package homework2;

import java.util.ArrayList;

public class Test {
    public static void main(String[] args) {

        ArrayList<Integer> list = new ArrayList<>();
        list.add(10);
        list.add(20);
        list.add(30);
        list.add(40);

        int index = listTest(list, 30);
        System.out.println("Index: " + index); // 输出：Index: 2

        index = listTest(list, 50);
        System.out.println("Index: " + index); // 输出：Index: -1
    }
    public static int listTest(ArrayList<Integer> list, Integer num) {
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).equals(num)) {
                return i;
            }
        }
        return -1;
    }
}
